<?php
// $Id$

include_once('BaseModel.class.php');

class PresetMessagesModel extends BaseModel
{
    function collect($offset=null,$limit=null,$search=array(),$by='1',$sort='',$u_id='',$u_prv='')
	{
		$where = ($search) ? "WHERE LOWER({$search['searchfield']}) LIKE '%{$search['searchtext']}%'" : "WHERE 1";

		if (is_null($offset)) {
            
	            $query = "SELECT COUNT(*) FROM preset_messages $where AND active=1";
		} else {
                    $query = "SELECT * FROM preset_messages $where AND active=1 ORDER BY $by $sort LIMIT $offset,$limit";
		}
		return $this->query($query, true);
    }

    function detail ($id)
    {
        $query = "SELECT * FROM preset_messages WHERE id='$id'";
        return $this->query($query, true);
    }

    /*
     * Add members and return the new member_id
     *
     */
    function ins($detail)
    {
        return $this->insert('preset_messages', $detail);
        return $this->last_insert_id('preset_messages');
    }

    /*
     * Update categories for a particular categories_id
     *
     */
    function edit ($id, $detail)
    {
        return $this->update('preset_messages', $detail, "id = '$id'");
    }

    /*
     * Delete members detail for a particular member_id
     *
     */

function check_prevdefault()
{
        $query = "SELECT  `id`  FROM `preset_messages` WHERE `default` = 1";
        return  $this->query($query, true);

}
    function update_prevdefault ($id)
    {
        $query = "UPDATE `preset_messages` SET `default` = '0', `modified_date` = NOW() WHERE `id` = $id";
        return  $this->query($query, false);
    }

    function deactivate ($id)
    {
        $query = "UPDATE preset_messages SET active = '0' WHERE id='$id'";
        return $this->query($query, false);
    }
    function activate ($id)
    {
        $query = "UPDATE preset_messages SET active = '1' WHERE id='$id'";
        return $this->query($query, false);
    }
}

?>
